<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        require_once '../model/db.php';
        require_once '../model/keywords.php';
        require_once '../model/Works.php';
        ?>
        <?php
        $keywords = new work();
        $list = $keywords->works1();
        ?>
    <from method='GET'>  
        <a href='index.php?page=1'> First</a>
        <?php if (isset($_GET['page'])) { ?>
            <a href='index.php?page=<?php echo $_GET['page'] - 1 ?>'> Prew </a>
        <?php } ?>
        <?php
        $page = 5;

        if ((isset($_GET['page'])) && ($_GET['page'] <= 3)) {
            for ($i = 1; $i <= $page; $i++) {
                ?> 
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
                <?php
            }
        } else if ((isset($_GET['page'])) && ($_GET['page'] >= 17)) {
            for ($i = 15; $i <= 19; $i++) {
                ?> 
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
            <?php
            }
        } else if (isset($_GET['page'])) {
            for ($i = ($_GET['page'] - 2); $i <= ($_GET['page'] + 2); $i++) {
                ?>
                <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
            <?php }
        } 
            else{
            ?>
        <a href='index.php'> Prew </a>
        <?php for ($i = 1; $i <= 5; $i++) { ?>
            <a href='index.php?page=<?php echo $i ?>'><?php echo $i ?></a>
        <?php } ?>
        <a href='index.php?page=2'> Next </a>
            <?php }?>
        <?php if (isset($_GET['page'])) { ?>
            <a href='index.php?page=<?php echo $_GET['page'] + 1 ?>'> Next </a>
<?php } ?>
        <a href='index.php?page=19'>Last</a>
    </table>
</from>
<?php
$page = 1;
if (isset($_GET['page']))
    $page = $_GET['page'];
$from = PER_PAGE * ($page - 1);
$to = PER_PAGE;
$query = "SELECT * FROM works LIMIT $from ,$to";
$list = $keywords->select($query);
?>
</from>
<table border="1px">
    <tr>
        <td>ID</td>
        <td>Name</td>
        <td>URL</td>
    </tr>
<?php foreach ($list as $lists) : ?> 
        <tr>
            <td><?php echo $lists['id']; ?></td>
            <td><?php echo $lists['name']; ?></td>
            <td><a href='<?php echo $lists['url']; ?>'><?php echo $lists['url']; ?></tr>
<?php endforeach; ?>
</table>

</body>